import Mock from 'mockjs'
var billCategory = Mock.mock({
    'list|50': [{
        'id|+1': 1,
        categoryName: '单据分类@id',
        'status|1': [0, 1, 2, 3, 4],
        "parentId|1-100": 10,
        categoryCode: '000@id',
        remark: '@csentence(0,50)',
    }]
})
export default [
    // 单据分类分页
    {
        url: '/bill/category/getAllFormCategoryList',
        type: 'post',
        response: config => {
            let { pageSize = 10, currentPage = 1 } = config.body
            const total = billCategory.list.length
            let list = billCategory.list.slice(pageSize * (currentPage - 1), currentPage * pageSize)
            return {
                code: 20000,
                data: {
                    list,
                    currentPage,
                    pageSize,
                    totalCount: total,
                    totalPages: (total + pageSize - 1) / pageSize,
                }
            }
        }
    },
    // 单据分类删除
    {
        url: '/bill/category/dropFormCategory',
        type: 'post',
        response: config => {
            const { id } = config.body
            if (!id) {
                return {
                    code: 403,
                    msg: '删除失败',
                    data: null
                }
            }
            return {
                code: 20000,
                msg: '处理成功',
                data: id
            }
        }
    },
    // 单据分类增加
    {
        url: '/task/category/add',
        type: 'post',
        response: config => {
            const { categoryName, remark } = config.body
            if (!categoryName) {
                return {
                    code: 20203,
                    msg: 'categoryName is require',
                    data: null
                }
            }
            let data = {
                id: category.id,
                categoryName,
                remark
            }
            return {
                code: 20000,
                msg: '处理成功',
                data,
            }
        }
    },
    // 单据分类修改
    {
        url: '/bill/category/editFormCategory',
        type: 'post',
        response: config => {
            const { id, categoryName, remark } = config.body
            if (!categoryName || !id) {
                return {
                    code: 20203,
                    msg: 'id and categoryName is require',
                    data: null
                }
            }
            let data = {
                id: category.id,
                categoryName,
                remark
            }
            return {
                code: 20000,
                msg: '处理成功',
                data,
            }
        }
    },
]